<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/css/main.css">
    <script src="/js/jquery-2.1.4.min.js"></script>


    <link rel="stylesheet" href="/css/commonNav.css">
    <style>


    </style>
</head>
<body class="lay-blog">
<div th:include="/teacher/templates::header"></div>


<div class="container-wrap">

    <div class="container" style="width: 1100px;">
        <div class="main" style="">
            <div class="left-container" style="">
                <ul class="layui-nav layui-nav-tree left-nav" style="background-color: white;color: black;"
                    lay-filter="test">
                    <li class="layui-nav-item"><a href="/teacher/userInfo/index.html">基本信息</a></li>
                    <li class="layui-nav-item active">
                        <a href="/teacher/userInfo/updatePwd.html">修改密码</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="/teacher/userInfo/updateMail.html">修改邮箱</a>
                    </li>
                </ul>
            </div>
            <div class="right-content" style="background-color: white; padding: 20px 30px 20px 0px;">
                <div class="" id="outline">
                    <div class="layui-row">
                        <div style="padding-left: 20px; margin-bottom: 30px;">
                            <h3 style="font-size: 20px;color: #3d3d3d;font-weight: bold">修改密码</h3>
                        </div>
                        <hr>
                        <form class="layui-form layui-col-md12 x-so" lay-filter="pwd-form" style="font-size: 13px;">
                            <div class="layui-form-item">
                                <label class="layui-form-label">原密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="oldPwd" required lay-verify="required" placeholder="原密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">新密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="pwd" required lay-verify="required" placeholder="新密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">确认密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="confirmPwd" required lay-verify="required" placeholder="确认密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="pwd-submit">立即提交</button>
                                </div>
                            </div>
                        </form>
                    </div>


                </div>
            </div>


            <div style="clear: both;"></div>
        </div>
    </div>
</div>
<div th:include="/teacher/templates::footer"></div>


<script>
    layui.use('form', function (form) {
        form.on('submit(pwd-submit)', function (data) {
            var oldPwd = data.field.oldPwd;
            var pwd = data.field.pwd;
            var confirmPwd= data.field.confirmPwd;
            if(pwd != confirmPwd){
                layui.layer.msg('密码不一致', {icon:2})
                return false;
            }
            if(oldPwd == confirmPwd){
                layui.layer.msg('新密码不能和旧密码一样', {icon:2})
                return false;
            }
            $.ajax({
                url:'/api/user/updatePwd',
                type:'post',
                data:{oldPwd, pwd},
                success:function (res) {
                    if(res.code==0){
                        layui.layer.msg('修改成功', {icon:1})
                        window.location.href = '/login.html'
                    }
                }
            })
            return false;
        })
    })
</script>
</body>
</html>